package com.xdw.vuebackdemo.controller;

import com.xdw.vuebackdemo.base.common.ApiResult;
import com.xdw.vuebackdemo.model.Permission;
import com.xdw.vuebackdemo.service.PermissionService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Set;
/**
 * @author xiadewang
 */
@RestController
@RequestMapping("/api")
public class MenuListContoller {
    private Logger logger = LoggerFactory.getLogger(MenuListContoller.class);
    @Autowired
    PermissionService permissionService;
    @RequestMapping("/getMenuList")
    public ApiResult<Set<Permission>> getMenuList(HttpServletRequest request){
        logger.info("getMenuList");
        Set<Permission> permissionList= null;
        String userIdStr = String.valueOf(request.getAttribute("userId"));
        if(StringUtils.isNotBlank(userIdStr)){
            long userId = Long.parseLong(userIdStr);
            permissionList = permissionService.getPermissonListByUserId(userId);
        }
        return ApiResult.success(permissionList);
    }
}
